package org.edu.service.impl;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.edu.bean.Role;
import org.edu.bean.Role_user;
import org.edu.bean.User;
import org.edu.dao.RoleDao;
import org.edu.service.RoleService;
import org.springframework.stereotype.Service;

@Service
public class RoleServiceImpl implements RoleService {

	@Resource
	RoleDao roleDao ;

	@SuppressWarnings("unchecked")
	public List<Role> selectRole_User(User user) {
		List role_userList = roleDao.selectRole_User(user.getId());
		List<Role> roles = new ArrayList<Role>();
		Role_user roleUser ;
		for(int i= 0 ; i<role_userList.size() ; i++){
			roleUser = (Role_user)role_userList.get(i);
			Role role = roleDao.selectRoleFromUser(roleUser);
			if(role!=null){
				roles.add(role);
			}
		}
		return roles ;
	}

	public List<Role> selectRole() {
		List <Role> roles = roleDao.selectRoles() ;
		return roles;
	}

	public Integer createRole(Role role) {
		// TODO Auto-generated method stub
		return roleDao.createRole(role);
	}

	public boolean delRole(Role role) {
		return roleDao.delRole(role);
	}

	public Role getRoleById(int id) {
		return roleDao.getRoleById(id);
	}
	
	
	

}
